package com.saxon.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class jsFilter implements Filter {
    @Override
    public void init (FilterConfig filterConfig) throws ServletException {

    }

    //防止前端代码的乱码问题
    @Override
    public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        if (req.getHeader ("RequestType") != null && req.getHeader ("RequestType").equalsIgnoreCase ("ajax")) {
            request.setCharacterEncoding ("utf-8");
        } else {
            request.setCharacterEncoding ("gbk");
        }
        chain.doFilter (request, response);
    }

    @Override
    public void destroy () {

    }
}

